#ifndef HEADER_fd_src_discof_bank_fd_bank_err_h
#define HEADER_fd_src_discof_bank_fd_bank_err_h

#include "../../util/log/fd_log.h"
#include "../../flamenco/runtime/fd_runtime_err.h"
#include "../../disco/metrics/generated/fd_metrics_enums.h"


static inline int
fd_bank_err_from_runtime_err( int err ) {
   switch( err ) {
      case FD_RUNTIME_EXECUTE_SUCCESS:                                 return FD_METRICS_ENUM_TRANSACTION_RESULT_V_SUCCESS_IDX;

      case FD_RUNTIME_TXN_ERR_INSTRUCTION_ERROR:                       return FD_METRICS_ENUM_TRANSACTION_RESULT_V_INSTRUCTON_ERROR_IDX;

      case FD_RUNTIME_TXN_ERR_ACCOUNT_NOT_FOUND:                       return FD_METRICS_ENUM_TRANSACTION_RESULT_V_ACCOUNT_NOT_FOUND_IDX;
      case FD_RUNTIME_TXN_ERR_PROGRAM_ACCOUNT_NOT_FOUND:               return FD_METRICS_ENUM_TRANSACTION_RESULT_V_PROGRAM_ACCOUNT_NOT_FOUND_IDX;
      case FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_FEE:              return FD_METRICS_ENUM_TRANSACTION_RESULT_V_INSUFFICIENT_FUNDS_FOR_FEE_IDX;
      case FD_RUNTIME_TXN_ERR_INVALID_ACCOUNT_FOR_FEE:                 return FD_METRICS_ENUM_TRANSACTION_RESULT_V_INVALID_ACCOUNT_FOR_FEE_IDX;
      case FD_RUNTIME_TXN_ERR_ALREADY_PROCESSED:                       return FD_METRICS_ENUM_TRANSACTION_RESULT_V_ALREADY_PROCESSED_IDX;
      case FD_RUNTIME_TXN_ERR_BLOCKHASH_NOT_FOUND:                     return FD_METRICS_ENUM_TRANSACTION_RESULT_V_BLOCKHASH_NOT_FOUND_IDX;
      case FD_RUNTIME_TXN_ERR_BLOCKHASH_FAIL_ADVANCE_NONCE_INSTR:      return FD_METRICS_ENUM_TRANSACTION_RESULT_V_NONCE_ADVANCE_FAILED_IDX;
      case FD_RUNTIME_TXN_ERR_BLOCKHASH_FAIL_WRONG_NONCE:              return FD_METRICS_ENUM_TRANSACTION_RESULT_V_NONCE_WRONG_BLOCKHASH_IDX;
      case FD_RUNTIME_TXN_ERR_BLOCKHASH_NONCE_ALREADY_ADVANCED:        return FD_METRICS_ENUM_TRANSACTION_RESULT_V_NONCE_ALREADY_ADVANCED_IDX;
      case FD_RUNTIME_TXN_ERR_INVALID_PROGRAM_FOR_EXECUTION:           return FD_METRICS_ENUM_TRANSACTION_RESULT_V_INVALID_PROGRAM_FOR_EXECUTION_IDX;
      case FD_RUNTIME_TXN_ERR_ADDRESS_LOOKUP_TABLE_NOT_FOUND:          return FD_METRICS_ENUM_TRANSACTION_RESULT_V_ADDRESS_LOOKUP_TABLE_NOT_FOUND_IDX;
      case FD_RUNTIME_TXN_ERR_INVALID_ADDRESS_LOOKUP_TABLE_OWNER:      return FD_METRICS_ENUM_TRANSACTION_RESULT_V_INVALID_ADDRESS_LOOKUP_TABLE_OWNER_IDX;
      case FD_RUNTIME_TXN_ERR_INVALID_ADDRESS_LOOKUP_TABLE_DATA:       return FD_METRICS_ENUM_TRANSACTION_RESULT_V_INVALID_ADDRESS_LOOKUP_TABLE_DATA_IDX;
      case FD_RUNTIME_TXN_ERR_INVALID_ADDRESS_LOOKUP_TABLE_INDEX:      return FD_METRICS_ENUM_TRANSACTION_RESULT_V_INVALID_ADDRESS_LOOKUP_TABLE_INDEX_IDX;
      case FD_RUNTIME_TXN_ERR_MAX_LOADED_ACCOUNTS_DATA_SIZE_EXCEEDED:  return FD_METRICS_ENUM_TRANSACTION_RESULT_V_MAX_LOADED_ACCOUNTS_DATA_SIZE_EXCEEDED_IDX;
      case FD_RUNTIME_TXN_ERR_DUPLICATE_INSTRUCTION:                   return FD_METRICS_ENUM_TRANSACTION_RESULT_V_DUPLICATE_INSTRUCTION_IDX;
      case FD_RUNTIME_TXN_ERR_INVALID_LOADED_ACCOUNTS_DATA_SIZE_LIMIT: return FD_METRICS_ENUM_TRANSACTION_RESULT_V_INVALID_LOADED_ACCOUNTS_DATA_SIZE_LIMIT_IDX;

      case FD_RUNTIME_TXN_ERR_ACCOUNT_IN_USE:                          return FD_METRICS_ENUM_TRANSACTION_RESULT_V_ACCOUNT_IN_USE_IDX;
      case FD_RUNTIME_TXN_ERR_ACCOUNT_LOADED_TWICE:                    return FD_METRICS_ENUM_TRANSACTION_RESULT_V_ACCOUNT_LOADED_TWICE_IDX;
      case FD_RUNTIME_TXN_ERR_SIGNATURE_FAILURE:                       return FD_METRICS_ENUM_TRANSACTION_RESULT_V_SIGNATURE_FAILURE_IDX;
      case FD_RUNTIME_TXN_ERR_TOO_MANY_ACCOUNT_LOCKS:                  return FD_METRICS_ENUM_TRANSACTION_RESULT_V_TOO_MANY_ACCOUNT_LOCKS_IDX;

      case FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_RENT:             return FD_METRICS_ENUM_TRANSACTION_RESULT_V_INSUFFICIENT_FUNDS_FOR_RENT_IDX;
      case FD_RUNTIME_TXN_ERR_UNBALANCED_TRANSACTION:                  return FD_METRICS_ENUM_TRANSACTION_RESULT_V_UNBALANCED_TRANSACTION_IDX;

      case FD_RUNTIME_TXN_ERR_CALL_CHAIN_TOO_DEEP:
      case FD_RUNTIME_TXN_ERR_MISSING_SIGNATURE_FOR_FEE:
      case FD_RUNTIME_TXN_ERR_INVALID_ACCOUNT_INDEX:
      case FD_RUNTIME_TXN_ERR_SANITIZE_FAILURE:
      case FD_RUNTIME_TXN_ERR_CLUSTER_MAINTENANCE:
      case FD_RUNTIME_TXN_ERR_ACCOUNT_BORROW_OUTSTANDING:
      case FD_RUNTIME_TXN_ERR_WOULD_EXCEED_MAX_BLOCK_COST_LIMIT:
      case FD_RUNTIME_TXN_ERR_UNSUPPORTED_VERSION:
      case FD_RUNTIME_TXN_ERR_INVALID_WRITABLE_ACCOUNT:
      case FD_RUNTIME_TXN_ERR_WOULD_EXCEED_MAX_ACCOUNT_COST_LIMIT:
      case FD_RUNTIME_TXN_ERR_WOULD_EXCEED_ACCOUNT_DATA_BLOCK_LIMIT:
      case FD_RUNTIME_TXN_ERR_INVALID_RENT_PAYING_ACCOUNT:
      case FD_RUNTIME_TXN_ERR_WOULD_EXCEED_MAX_VOTE_COST_LIMIT:
      case FD_RUNTIME_TXN_ERR_WOULD_EXCEED_ACCOUNT_DATA_TOTAL_LIMIT:
      case FD_RUNTIME_TXN_ERR_RESANITIZATION_NEEDED:
      case FD_RUNTIME_TXN_ERR_PROGRAM_EXECUTION_TEMPORARILY_RESTRICTED:
      case FD_RUNTIME_TXN_ERR_PROGRAM_CACHE_HIT_MAX_LIMIT:
      default: FD_LOG_ERR(( "Unknown runtime error %d", err ));
    }

    return 0;
}

#endif /* HEADER_fd_src_discof_bank_fd_bank_err_h */
